/*
 * BatteryMeterSystemView.java
 */
package bms;

import bms.model.Battery;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Point;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.Task;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.ScrollPaneLayout;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.dial.DialBackground;
import org.jfree.chart.plot.dial.DialCap;
import org.jfree.chart.plot.dial.DialPlot;
import org.jfree.chart.plot.dial.DialTextAnnotation;
import org.jfree.chart.plot.dial.DialValueIndicator;
import org.jfree.chart.plot.dial.StandardDialFrame;
import org.jfree.chart.plot.dial.StandardDialRange;
import org.jfree.chart.plot.dial.StandardDialScale;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.general.DefaultValueDataset;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.GradientPaintTransformType;
import org.jfree.ui.StandardGradientPaintTransformer;

/**
 * The application's main frame.
 */
public class BatteryMeterSystemView extends FrameView {

    String strnum = "";
    DefaultValueDataset dataset1;
    DefaultValueDataset dataset2;
    Battery curBattery;

    public BatteryMeterSystemView(SingleFrameApplication app) {
        super(app);

        initComponents();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String) (evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer) (evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = BatteryMeterSystem.getApplication().getMainFrame();
            aboutBox = new BatteryMeterSystemAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        BatteryMeterSystem.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        txtBatteryNumber = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        btnOne = new javax.swing.JButton();
        btnTwo = new javax.swing.JButton();
        btnThree = new javax.swing.JButton();
        btnFour = new javax.swing.JButton();
        btnFive = new javax.swing.JButton();
        btnSix = new javax.swing.JButton();
        btnSeven = new javax.swing.JButton();
        btnEight = new javax.swing.JButton();
        btnNine = new javax.swing.JButton();
        jBttnViewBattery = new javax.swing.JButton();
        btnZero = new javax.swing.JButton();
        jButton13 = new javax.swing.JButton();
        jBttnClear = new javax.swing.JButton();
        btnExport = new javax.swing.JButton();
        btnPageRight = new javax.swing.JButton();
        btnPageLeft = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        pnlDisplay = new javax.swing.JPanel();
        pnlMeter = new javax.swing.JPanel();
        pnlBatteryVoltsReadings = new javax.swing.JScrollPane();
        pnlBatteryTempReading = new javax.swing.JScrollPane();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();

        mainPanel.setName("mainPanel"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(bms.BatteryMeterSystem.class).getContext().getResourceMap(BatteryMeterSystemView.class);
        jPanel1.setBackground(resourceMap.getColor("jPanel1.background")); // NOI18N
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jPanel1.border.title"), javax.swing.border.TitledBorder.LEADING, javax.swing.border.TitledBorder.TOP, resourceMap.getFont("jPanel1.border.titleFont"), resourceMap.getColor("jPanel1.border.titleColor"))); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        txtBatteryNumber.setText(resourceMap.getString("txtBatteryNumber.text")); // NOI18N
        txtBatteryNumber.setName("txtBatteryNumber"); // NOI18N

        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N

        btnOne.setText(resourceMap.getString("jBttn1.text")); // NOI18N
        btnOne.setName("jBttn1"); // NOI18N
        btnOne.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOneActionPerformed(evt);
            }
        });

        btnTwo.setText(resourceMap.getString("jBttn2.text")); // NOI18N
        btnTwo.setName("jBttn2"); // NOI18N

        btnThree.setText(resourceMap.getString("jBttn3.text")); // NOI18N
        btnThree.setName("jBttn3"); // NOI18N

        btnFour.setText(resourceMap.getString("btnFour.text")); // NOI18N
        btnFour.setName(resourceMap.getString("btnFour.name")); // NOI18N

        btnFive.setText(resourceMap.getString("jBttn5.text")); // NOI18N
        btnFive.setName("jBttn5"); // NOI18N

        btnSix.setText(resourceMap.getString("jBttn6.text")); // NOI18N
        btnSix.setName("jBttn6"); // NOI18N

        btnSeven.setText(resourceMap.getString("jBttn7.text")); // NOI18N
        btnSeven.setName("jBttn7"); // NOI18N

        btnEight.setText(resourceMap.getString("jBttn8.text")); // NOI18N
        btnEight.setName("jBttn8"); // NOI18N

        btnNine.setText(resourceMap.getString("jBttn9.text")); // NOI18N
        btnNine.setName("jBttn9"); // NOI18N

        jBttnViewBattery.setText(resourceMap.getString("jBttnViewBattery.text")); // NOI18N
        jBttnViewBattery.setName("jBttnViewBattery"); // NOI18N
        jBttnViewBattery.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBttnViewBatteryActionPerformed(evt);
            }
        });

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(bms.BatteryMeterSystem.class).getContext().getActionMap(BatteryMeterSystemView.class, this);
        btnZero.setAction(actionMap.get("ButtonZeroClicked")); // NOI18N
        btnZero.setText(resourceMap.getString("jBttn0.text")); // NOI18N
        btnZero.setName("jBttn0"); // NOI18N

        jButton13.setText(resourceMap.getString("jButton13.text")); // NOI18N
        jButton13.setName("jButton13"); // NOI18N
        jButton13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton13ActionPerformed(evt);
            }
        });

        jBttnClear.setText(resourceMap.getString("jBttnClear.text")); // NOI18N
        jBttnClear.setName("jBttnClear"); // NOI18N
        jBttnClear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBttnClearActionPerformed(evt);
            }
        });

        btnExport.setText(resourceMap.getString("btnExport.text")); // NOI18N
        btnExport.setName("btnExport"); // NOI18N

        btnPageRight.setText(resourceMap.getString("btnPageRight.text")); // NOI18N
        btnPageRight.setEnabled(false);
        btnPageRight.setName("btnPageRight"); // NOI18N

        btnPageLeft.setText(resourceMap.getString("btnPageLeft.text")); // NOI18N
        btnPageLeft.setEnabled(false);
        btnPageLeft.setName("btnPageLeft"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addComponent(btnFour, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnFive, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnSix, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addComponent(btnPageLeft, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnZero, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnPageRight, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addComponent(btnSeven, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnEight, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnNine, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(btnOne, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnTwo, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(btnThree, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(txtBatteryNumber, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jBttnClear, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addComponent(jBttnViewBattery, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addComponent(jButton13, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addComponent(btnExport, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBttnClear, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtBatteryNumber, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnOne, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnTwo, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnThree, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnFour, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnFive, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnSix, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSeven, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnEight, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnNine, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnZero, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnPageRight, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnPageLeft, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jBttnViewBattery, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton13, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnExport, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        pnlDisplay.setBackground(resourceMap.getColor("pnlDisplay.background")); // NOI18N
        pnlDisplay.setAutoscrolls(true);
        pnlDisplay.setName("pnlDisplay"); // NOI18N

        pnlMeter.setBackground(resourceMap.getColor("pnlMeter.background")); // NOI18N
        pnlMeter.setName("pnlMeter"); // NOI18N

        javax.swing.GroupLayout pnlMeterLayout = new javax.swing.GroupLayout(pnlMeter);
        pnlMeter.setLayout(pnlMeterLayout);
        pnlMeterLayout.setHorizontalGroup(
            pnlMeterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 326, Short.MAX_VALUE)
        );
        pnlMeterLayout.setVerticalGroup(
            pnlMeterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 301, Short.MAX_VALUE)
        );

        pnlBatteryVoltsReadings.setName("pnlBatteryVoltsReadings"); // NOI18N

        pnlBatteryTempReading.setName("pnlBatteryTempReading"); // NOI18N

        javax.swing.GroupLayout pnlDisplayLayout = new javax.swing.GroupLayout(pnlDisplay);
        pnlDisplay.setLayout(pnlDisplayLayout);
        pnlDisplayLayout.setHorizontalGroup(
            pnlDisplayLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDisplayLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnlMeter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlDisplayLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pnlBatteryTempReading, javax.swing.GroupLayout.DEFAULT_SIZE, 640, Short.MAX_VALUE)
                    .addComponent(pnlBatteryVoltsReadings, javax.swing.GroupLayout.DEFAULT_SIZE, 640, Short.MAX_VALUE))
                .addContainerGap())
        );
        pnlDisplayLayout.setVerticalGroup(
            pnlDisplayLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDisplayLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlDisplayLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pnlMeter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(pnlBatteryVoltsReadings, javax.swing.GroupLayout.PREFERRED_SIZE, 352, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(pnlBatteryTempReading, javax.swing.GroupLayout.PREFERRED_SIZE, 352, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(99, 99, 99))
        );

        jScrollPane1.setViewportView(pnlDisplay);

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 994, Short.MAX_VALUE))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 825, Short.MAX_VALUE)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(478, Short.MAX_VALUE))
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 1207, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 1037, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

private void btnOneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOneActionPerformed
// TODO add your handling code here:
    strnum += Integer.toString(2);
    txtBatteryNumber.setText(strnum);
}//GEN-LAST:event_btnOneActionPerformed

private void jBttnClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBttnClearActionPerformed
// TODO add your handling code here:
    txtBatteryNumber.setText("");
    strnum = "";
}//GEN-LAST:event_jBttnClearActionPerformed

    /*
    JPanel card2 = new JPanel();
    card2.add(new JTextField("TextField", 20));
     */
private void jBttnViewBatteryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBttnViewBatteryActionPerformed
    // TODO add your handling code here:    
    curBattery = new Battery();
    String strnum = txtBatteryNumber.getText().toString();

    if (curBattery.checkBattery(strnum)) {
        pnlMeter.setLayout(new java.awt.BorderLayout());
        pnlMeter.add(new BatteryMeter(curBattery.findBatteryByNum(strnum)));
        pnlMeter.validate();

        pnlBatteryTempReading.setLayout(new ScrollPaneLayout());
        pnlBatteryTempReading.setHorizontalScrollBarPolicy(jScrollPane1.HORIZONTAL_SCROLLBAR_ALWAYS);
        pnlBatteryTempReading.setVerticalScrollBarPolicy(jScrollPane1.VERTICAL_SCROLLBAR_NEVER);
        pnlBatteryTempReading.getViewport().add(createBatteryUniqueMeterTemperature(curBattery.findBatteryByNum(strnum)));
        pnlBatteryTempReading.validate();

        pnlBatteryVoltsReadings.setLayout(new ScrollPaneLayout());
        pnlBatteryVoltsReadings.setHorizontalScrollBarPolicy(jScrollPane1.HORIZONTAL_SCROLLBAR_ALWAYS);
        pnlBatteryVoltsReadings.setVerticalScrollBarPolicy(jScrollPane1.VERTICAL_SCROLLBAR_NEVER);
        pnlBatteryVoltsReadings.getViewport().add(createBatteryUniqueMeterVoltage(curBattery.findBatteryByNum(strnum)), null);
        pnlBatteryVoltsReadings.validate();

    } else {
        //    String toString = curBattery.toString();
        pnlMeter.setLayout(new java.awt.BorderLayout());
        //pnlMeter.add(createDemoPanel(), BorderLayout.CENTER);
        pnlMeter.removeAll();
        pnlMeter.validate();

    }
}//GEN-LAST:event_jBttnViewBatteryActionPerformed

private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton13ActionPerformed
// TODO add your handling code here:

    pnlMeter.hide();
    pnlDisplay.validate();

    pnlBatteryTempReading.setLayout(new ScrollPaneLayout());
    pnlBatteryTempReading.setHorizontalScrollBarPolicy(jScrollPane1.HORIZONTAL_SCROLLBAR_ALWAYS);
    pnlBatteryTempReading.setVerticalScrollBarPolicy(jScrollPane1.VERTICAL_SCROLLBAR_NEVER);
    pnlBatteryTempReading.getViewport().add(createBatteryMeterTemperature());
    pnlBatteryTempReading.validate();

    //createBatteryMeterTemperature()
    pnlBatteryVoltsReadings.setLayout(new ScrollPaneLayout());
    pnlBatteryVoltsReadings.setHorizontalScrollBarPolicy(jScrollPane1.HORIZONTAL_SCROLLBAR_ALWAYS);
    pnlBatteryVoltsReadings.setVerticalScrollBarPolicy(jScrollPane1.VERTICAL_SCROLLBAR_NEVER);
    pnlBatteryVoltsReadings.getViewport().add(createBatteryMeterVoltage(), null);
    pnlBatteryVoltsReadings.validate();


    btnPageLeft.setEnabled(false);
    btnPageRight.setEnabled(true);

    /*
    if (curBattery.getNextFlag() && curBattery.getPreviousFlag()) {
    btnPageLeft.enable(true);
    btnPageRight.enable(true);
    }
     */
}//GEN-LAST:event_jButton13ActionPerformed

    @Action
    public Task ButtonZeroClicked() {
        return new ButtonZeroClickedTask(getApplication());
    }

    private class ButtonZeroClickedTask extends org.jdesktop.application.Task<Object, Void> {

        ButtonZeroClickedTask(org.jdesktop.application.Application app) {
            // Runs on the EDT.  Copy GUI state that
            // doInBackground() depends on from parameters
            // to ButtonZeroClickedTask fields, here.
            super(app);
        }

        @Override
        protected Object doInBackground() {
            // Your Task's code here.  This method runs
            // on a background thread, so don't reference
            // the Swing GUI from here.
            return null;  // return your result
        }

        @Override
        protected void succeeded(Object result) {
            // Runs on the EDT.  Update the GUI based on
            // the result computed by doInBackground().
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnEight;
    private javax.swing.JButton btnExport;
    private javax.swing.JButton btnFive;
    private javax.swing.JButton btnFour;
    private javax.swing.JButton btnNine;
    private javax.swing.JButton btnOne;
    private javax.swing.JButton btnPageLeft;
    private javax.swing.JButton btnPageRight;
    private javax.swing.JButton btnSeven;
    private javax.swing.JButton btnSix;
    private javax.swing.JButton btnThree;
    private javax.swing.JButton btnTwo;
    private javax.swing.JButton btnZero;
    private javax.swing.JButton jBttnClear;
    private javax.swing.JButton jBttnViewBattery;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton13;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JScrollPane pnlBatteryTempReading;
    private javax.swing.JScrollPane pnlBatteryVoltsReadings;
    private javax.swing.JPanel pnlDisplay;
    private javax.swing.JPanel pnlMeter;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JTextField txtBatteryNumber;
    // End of variables declaration//GEN-END:variables
    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;
    private JDialog aboutBox;

    static class BatteryMeter extends JPanel {

        public BatteryMeter(Battery battery) {

            //battery.toString();

            DefaultValueDataset dataset1 = new DefaultValueDataset(battery.getTemperature());
            DefaultValueDataset dataset2 = new DefaultValueDataset(battery.getVoltage());

            DialPlot dialplot = new DialPlot();
            dialplot.setView(0.0D, 0.0D, 1.0D, 1.0D);
            dialplot.setDataset(0, dataset1);
            dialplot.setDataset(1, dataset2);
            StandardDialFrame standarddialframe = new StandardDialFrame();
            standarddialframe.setBackgroundPaint(Color.lightGray);
            standarddialframe.setForegroundPaint(Color.darkGray);
            dialplot.setDialFrame(standarddialframe);
            GradientPaint gradientpaint = new GradientPaint(new Point(),
                    new Color(255, 255, 255), new Point(), new Color(170, 170,
                    220));
            DialBackground dialbackground = new DialBackground(gradientpaint);
            dialbackground.setGradientPaintTransformer(new StandardGradientPaintTransformer(
                    GradientPaintTransformType.VERTICAL));
            dialplot.setBackground(dialbackground);
            DialTextAnnotation dialtextannotation = new DialTextAnnotation(
                    "Temp   Volts");
            //dialtextannotation.setFont(new Font("Dialog", 1, 14));
            dialtextannotation.setRadius(0.69999999999999996D);
            dialplot.addLayer(dialtextannotation);

            DialValueIndicator dialvalueindicator = new DialValueIndicator(0);
            //dialvalueindicator.setFont(new Font("Dialog", 0, 10));
            dialvalueindicator.setOutlinePaint(Color.darkGray);
            dialvalueindicator.setRadius(0.59999999999999998D);
            dialvalueindicator.setAngle(-103D);
            dialplot.addLayer(dialvalueindicator);

            DialValueIndicator dialvalueindicator1 = new DialValueIndicator(1);
            //dialvalueindicator1.setFont(new Font("Dialog", 0, 10));
            dialvalueindicator1.setOutlinePaint(Color.red);
            dialvalueindicator1.setRadius(0.59999999999999998D);
            dialvalueindicator1.setAngle(-77D);
            dialplot.addLayer(dialvalueindicator1);

            StandardDialScale standarddialscale = new StandardDialScale(0D,
                    85D, -130D, -285D, 10D, 4);
            standarddialscale.setTickRadius(0.88D);
            standarddialscale.setTickLabelOffset(0.14999999999999999D);
            //standarddialscale.setTickLabelFont(new Font("Dialog", 0, 14));
            dialplot.addScale(0, standarddialscale);

            StandardDialScale standarddialscale1 = new StandardDialScale(0D,
                    26D, -130D, -285D, 5D, 3);
            standarddialscale1.setTickRadius(0.5D);
            standarddialscale1.setTickLabelOffset(0.14999999999999999D);
            //standarddialscale1.setTickLabelFont(new Font("Dialog", 0, 10));
            standarddialscale1.setMajorTickPaint(Color.red);
            standarddialscale1.setMinorTickPaint(Color.red);
            dialplot.addScale(1, standarddialscale1);

            dialplot.mapDatasetToScale(1, 1);
            StandardDialRange standarddialrange = new StandardDialRange(24D,
                    25.5D, Color.RED);
            standarddialrange.setScaleIndex(1);
            standarddialrange.setInnerRadius(0.58999999999999997D);
            standarddialrange.setOuterRadius(0.58999999999999997D);
            dialplot.addLayer(standarddialrange);
            org.jfree.chart.plot.dial.DialPointer.Pin pin = new org.jfree.chart.plot.dial.DialPointer.Pin(
                    1);
            pin.setRadius(0.55000000000000004D);
            dialplot.addPointer(pin);
            org.jfree.chart.plot.dial.DialPointer.Pointer pointer = new org.jfree.chart.plot.dial.DialPointer.Pointer(
                    0);
            dialplot.addPointer(pointer);
            DialCap dialcap = new DialCap();
            dialcap.setRadius(0.10000000000000001D);
            dialplot.setCap(dialcap);

            JFreeChart jfreechart = new JFreeChart(dialplot);
            //jfreechart.setTitle("Battery " + batterynumber);

            ChartPanel chartpanel = new ChartPanel(jfreechart);
            chartpanel.setPreferredSize(new Dimension(326, 301));

            add(chartpanel);
        }
    }

    public static JPanel createBatteryMeterPanel() {
        return new BatteryMeterTemp();
    }

    static class BatteryMeterTemp extends JPanel {

        public BatteryMeterTemp() {
            Battery bd = new Battery();
            CategoryDataset dataset;

            dataset = bd.getTemperatureDataset();
            // create the chart...
            JFreeChart chart = ChartFactory.createLineChart(
                    "Battery Temperature", // chart title
                    "Battery", // domain axis label
                    "Temperature", // range axis label
                    dataset, // data
                    PlotOrientation.VERTICAL, // orientation
                    false, // include legend
                    true, // tooltips
                    false // urls
                    );
            chart.setBackgroundPaint(Color.white);

            CategoryPlot plot = (CategoryPlot) chart.getPlot();
            plot.setBackgroundPaint(Color.lightGray);
            plot.setRangeGridlinePaint(Color.white);

// customise the range axis...
            NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
            rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
// customise the renderer...
            LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
            renderer.setShapesVisible(true);
            renderer.setDrawOutlines(true);
            renderer.setUseFillPaint(true);
            renderer.setFillPaint(Color.white);

            ChartPanel chartTemps = new ChartPanel(chart);
            chartTemps.setPreferredSize(new Dimension(1200, 330));

            add(chartTemps);
        }
    }

    public JPanel createBatteryMeterVoltage() {
        return new BatteryMeterVolts();
    }

    class BatteryMeterVolts extends JPanel {

        public BatteryMeterVolts() {
            Battery bd = new Battery();
            CategoryDataset dataset;
            dataset = bd.getVoltageDataset();
            // create the chart...
            JFreeChart chart = ChartFactory.createLineChart(
                    "Battery Voltage", // chart title
                    "Battery", // domain axis label
                    "Volts", // range axis label
                    dataset, // data
                    PlotOrientation.VERTICAL, // orientation
                    false, // include legend
                    true, // tooltips
                    false // urls
                    );
            chart.setBackgroundPaint(Color.white);
            CategoryPlot plot = (CategoryPlot) chart.getPlot();
            plot.setBackgroundPaint(Color.lightGray);
            plot.setRangeGridlinePaint(Color.white);
// customise the range axis...
            NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
            rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
// customise the renderer...
            LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
            renderer.setShapesVisible(true);
            renderer.setDrawOutlines(true);
            renderer.setUseFillPaint(true);
            renderer.setFillPaint(Color.white);
            renderer.setItemLabelsVisible(true);

            ChartPanel charVolts = new ChartPanel(chart);
            charVolts.setPreferredSize(new Dimension(1200, 330));

            add(charVolts);
        }
    }

    public static JPanel createBatteryMeterTemperature() {
        return new BatteryMeterTemp();
    }

    public JPanel createBatteryUniqueMeterVoltage(Battery battery) {
        return new BatteryUniqueMeterVolts(battery);
    }

    class BatteryUniqueMeterVolts extends JPanel {

        public BatteryUniqueMeterVolts(Battery bd) {

            CategoryDataset dataset;
            dataset = bd.getUniqueVoltageDataset(bd.getBatteryNumber());
            // create the chart...
            JFreeChart chart = ChartFactory.createLineChart(
                    "Battery Voltage", // chart title
                    "Battery", // domain axis label
                    "Volts", // range axis label
                    dataset, // data
                    PlotOrientation.VERTICAL, // orientation
                    false, // include legend
                    true, // tooltips
                    false // urls
                    );
            chart.setBackgroundPaint(Color.white);
            CategoryPlot plot = (CategoryPlot) chart.getPlot();
            plot.setBackgroundPaint(Color.lightGray);
            plot.setRangeGridlinePaint(Color.white);
// customise the range axis...
            NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
            rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
// customise the renderer...
            LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
            renderer.setShapesVisible(true);
            renderer.setDrawOutlines(true);
            renderer.setUseFillPaint(true);
            renderer.setFillPaint(Color.white);
            renderer.setItemLabelsVisible(true);

            ChartPanel charVolts = new ChartPanel(chart);
            charVolts.setPreferredSize(new Dimension(1200, 330));

            add(charVolts);
        }
    }

    public JPanel createBatteryUniqueMeterTemperature(Battery battery) {
        return new BatteryUniqueMeterTemp(battery);
    }

    class BatteryUniqueMeterTemp extends JPanel {

        public BatteryUniqueMeterTemp(Battery bd) {

            CategoryDataset dataset;
            dataset = bd.getUniqueTemperatureDataset(bd.getBatteryNumber());
            // create the chart...
            JFreeChart chart = ChartFactory.createLineChart(
                    "Battery Temperature", // chart title
                    "Battery", // domain axis label
                    "Temperature", // range axis label
                    dataset, // data
                    PlotOrientation.VERTICAL, // orientation
                    false, // include legend
                    true, // tooltips
                    false // urls
                    );
            chart.setBackgroundPaint(Color.white);
            CategoryPlot plot = (CategoryPlot) chart.getPlot();
            plot.setBackgroundPaint(Color.lightGray);
            plot.setRangeGridlinePaint(Color.white);
// customise the range axis...
            NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
            rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
// customise the renderer...
            LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
            renderer.setShapesVisible(true);
            renderer.setDrawOutlines(true);
            renderer.setUseFillPaint(true);
            renderer.setFillPaint(Color.white);
            renderer.setItemLabelsVisible(true);

            ChartPanel charTemp = new ChartPanel(chart);
            charTemp.setPreferredSize(new Dimension(1200, 330));

            add(charTemp);
        }
    }
}
